<?php
class ml_model_rdsExtFollow extends ml_model_redis  
{    
    const EXT_FOLLOW = 'ef::';
    const TRD_TYPE = '3uid::';
    const TRD_TO_UID = '3id2uid::';
    
    function __construct() {
        if(!$this->init_rds('meila_cache'))
            return false;
    }
    
    public function get_extFollow($uid, $start = 0, $end = 4){
        
        $key = self::EXT_FOLLOW.$uid;
        
        return $this->lRange($key, $start, $end);
        
    }
    
    public function remove_extFollow($uid, $value){
        $key = self::EXT_FOLLOW.$uid;
        return $this->lRem($key, $value);
    }
    
    
    public function get_allKeys($key){
        
        return $this->keys($key.'*');
    }
    
    
    public function get_extFollow_count($uid) {
        $key = self::EXT_FOLLOW.$uid;
        
        return $this->lSize($key);
    }
    
    
    public function push_new_extFollow($meila_uid, $f_meila_uid, $type){
        
        $key = self::EXT_FOLLOW.$meila_uid;
        $value = intval($f_meila_uid);
        return $this->lPush($key, $value);
    }
    
    public function rpush_new_extFollow($meila_uid, $f_meila_uid, $type){
        
        $key = self::EXT_FOLLOW.$meila_uid;
        $value = intval($f_meila_uid);
        return $this->rPush($key, $value);
    }
    
    
    
    public function push_new_3rd($meila_uid, $type) {
        
        $key = self::TRD_TYPE.$type;
        $value = intval($meila_uid);
        
        return $this->sAdd($key, $value);
    }
    
    public function init_3rd_to_meilauid($trd_uid, $meila_uid, $type) {
        
        $hash_name = self::TRD_TO_UID.$type;
        $key = intval($trd_uid);
        $value = intval($meila_uid);
        
        return $this->hSet($hash_name, $key, $value);
    }
    
    public function get_meilauid_by_3rdid($trd_uid , $type){
        
        $hash_name = self::TRD_TO_UID.$type;
        $key = intval($trd_uid);
        
        return $this->hGet($hash_name, $key);
    }
    
    
    public function is_3rd($meila_uid, $type) {
        
        $key = self::TRD_TYPE.$type;
        $value = intval($meila_uid);
        
        return $this->sIsMember($key, $value);
    }
    
    public function get_my3rdFriend($meilauid, $type) {
        
        $key1 = self::TRD_TYPE.$type;
        $key2 = ml_model_atNick_rdsFollowList::PFX_SET_ATNICK_FOLLOWLIST.$meilauid;
        
        return $this->sInter($key1,$key2);
        
    } 

}